package com.bins.knowledge.point.algorithm;

import java.util.Arrays;

public class CandyForChildren {
    public static int findContentChildren(int[] childArr, int[] candyArr) {
        Arrays.sort(childArr);
        Arrays.sort(candyArr);

        int childIndex = 0;
        int candyIndex = 0;
        int contentCount = 0;

        while (childIndex < childArr.length && candyIndex < candyArr.length) {
            if (candyArr[candyIndex] >= childArr[childIndex]) {
                contentCount++;
                childIndex++;
            }
            candyIndex++;
        }

        return contentCount;
    }

    public static void main(String[] args) {
        int[] g = {1, 2, 3};
        int[] s = {1, 1, 2};

        int result = findContentChildren(g, s);
        System.out.println("最多能让 " + result + " 个小朋友满意！");
    }
}